{
 "cells": [
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. _installation:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    ".. meta::\n",
    "   :description: How to install pymoo, an open-source multi-objective optimization framework in Python."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    ".. meta::\n",
    "   :keywords: pymoo, PyPI, Python, Framework, Multi-objective Optimization"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Installation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you have not really worked with Python before, we recommend using [miniconda](https://docs.conda.io/en/latest/miniconda.html) or [anaconda](https://www.anaconda.com). Please follow the installation guides to set up a Python environment. For convenience we also provide a quick guide [below](#Conda)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Stable"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To install the most recent stable release of *pymoo* please use **PiPy**"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. code:: bash\n",
    "\n",
    "    pip install -U pymoo"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For MacOSX and Windows **compiled** packages are available.  For Linux the package will be compiled during installation (make sure that **NumPy** is installed before executing the **pip** command). If you encounter any difficulties during compilation or you prefer to compile the package by yourself please the our guide [below](#Compilation)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To quickly check if the compilation was successful you can use the following command:"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. code:: bash\n",
    "\n",
    "    python -c \"from pymoo.util.function_loader import is_compiled;print('Compiled Extensions: ', is_compiled())\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Release Candidate"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To install the current release candidate you simply have to add `--pre` to the installation command:"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. code:: bash\n",
    "\n",
    "    pip install --pre -U pymoo"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Development"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you intend to use not the latest development, select the branch you intend to use (below it is master) and install it by:"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    "\n",
    ".. code:: bash\n",
    "\n",
    "    pip install numpy\n",
    "    git clone https://github.com/anyoptimization/pymoo\n",
    "    cd pymoo\n",
    "    make compile\n",
    "    pip install ."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Compilation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The *pymoo* framework can be run with and without compiled modules. Some computationally more\n",
    "expensive function has been implemented using [Cython](https://github.com/cython/cython) for speedup. \n",
    "\n",
    "The compilation requires *NumPy* to be installed because its header files are needed. \n",
    "You can use the make command below directly:"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. code:: bash\n",
    "\n",
    "    make compile"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Or execute the same command by"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. code:: bash\n",
    "\n",
    "    python setup.py build_ext --inplace"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Or if Cython shall be used to create the `cpp` files from scratch use"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. code:: bash\n",
    "\n",
    "    python setup.py build_ext --inplace --cythonize"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "All the commands above will show you detailed error messages if the compilation has failed."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Windows**: For Windows you have to install C++ Distributable Library to compile the modules available [here](https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Conda"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Please check if conda is available in the command line:"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. code:: bash\n",
    "\n",
    "    conda --version"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you are already familiar with conda you might want to use an environment you have\n",
    "already created, or you might need *pymoo* in an existing one.\n",
    "\n",
    "Otherwise, create a new python environment with NumPy preinstalled and activate it:"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. code:: bash\n",
    "\n",
    "    conda create -n pymoo -y python==3.9 numpy\n",
    "    conda activate pymoo\n",
    "    pip install -U pymoo"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If the environment is not set up correctly, the installation will NOT fail and you\n",
    "will still be able to use *pymoo* without the benefit of the compiled modules."
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
